package com.qf.springBeanLifecyleDemo.until;

import org.springframework.beans.factory.FactoryBean;

import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 * @author 刘欣
 * @createTime 2022/12/28 19:19
 * @description
 */
public class MyFactoryBean implements FactoryBean<BufferedWriter> {

    private String fielPath;


    @Override
    public BufferedWriter getObject() throws Exception {
        System.out.println("BufferedWriter依赖注入");
        BufferedWriter writer = new BufferedWriter(new FileWriter(fielPath));
        return writer;
    }

    @Override
    public Class<?> getObjectType() {
        return BufferedWriter.class;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public void init() {
        System.out.println("writer对象初始化");
    }

    public void destroy() {
        System.out.println("writer对象销毁对象的方法");
    }

    public void setFielPath(String fielPath) {
        System.out.println("filePath注入");
        this.fielPath = fielPath;
    }

}
